package com.lyp.lease.web.admin.custom.converter;

import com.lyp.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;


public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String code) {

        for (ItemType type : ItemType.values()) {
            if (type.getCode().equals(Integer.parseInt(code))){
                return type;
            }
        }
        throw new IllegalArgumentException("code只能是1或2");
    }
}
